#include "Bullet.hpp"
#include <GL\freeglut.h>

Bullet::Bullet()
{
  life_ = 0;
  speed_ = 2.0f;
}

Bullet::~Bullet()
{
}

void Bullet::privateInit()
{

}

void Bullet::privateRender()
{
  if(!isDead())
  {
	double anim = secondsLived_ * 50;
	double colorPhase = sin(anim);

	if(colorPhase > 0.0 )
	  glColor3f(1,0,0);
	else
	  glColor3f(1,1,0);

	glutSolidSphere(2,6,6);
  }
}


void Bullet::privateUpdate()
{
  if( !isDead() )
  {
	translate(matrix_, dir[0], dir[1], dir[2]);
	secondsLived_ += sslf_;
	//! if bullet is old, kill it, set life_ = 0
	if(secondsLived_ >= 2.0) life_ = 0; 
  }
}

bool Bullet::isDead()
{
  return life_ <= 0;
}

bool Bullet::isAlive()
{
  return life_ > 0;
}

void Bullet::setAlive()
{
  life_ = 100;
  secondsLived_ = 0.0;
}

void Bullet::setDead()
{
  life_ = 0;
}

//! normalized vector expected
void Bullet::setDir(Vec3f d)
{
  dir = d * speed_;
}
